<?php
/**
 * common repository file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2019/08/20
 * Time: 06:07
 */

namespace HiCommon\Repository;

use HiCommon\Model\Equities;

class EquitiesRepository extends BaseRepository
{
    public function base_model(){
        return new \HiCommon\Model\Equities();
    }


    /**
     *  根据条件获取全部数据
     *  hinq 2019 08 23
     *
     */
    public function get_all( array $arr_option = [] )
    {
        return Equities::commonget($arr_option);
    }


    /**
     * 分页获取全部数据
     *
     * @param array $arr_option
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function get_list( array $arr_search, $arr_option = [])
    {
        return Equities::where(
        function ($query)
        use($arr_search) {
            if(!empty($arr_search['name'])){
                $query->where('name', 'like', '%'.$arr_search['name'].'%');
            }
        })->commonpage($arr_option);
    }


    /**
     * 添加一条数据
     *
     * @param array $arr_input
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function add_one( array $arr_input)
    {   
        return Equities::create($arr_input);
    }

    /**
     *  根据主键获取一条数据
     *  hinq 2019 08 22
     *
     **/
    public function get_one( int $nId , array $field = []){
        return Equities::commonfind( (int) $nId, (array) $field);
    }


    /**
     * 编辑一条数据
     *
     * @param array $arr_input
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function edit_one( array $arr_input)
    {
        return Equities::where('id',$arr_input['id'])->update($arr_input);
    }

	
    /**
     *  删除指定的数据
     *  hinq 2019 08 22
     *
     **/
    public function delete_one( int $nId ){
        return Equities::where('id', $nId)->commondelete();
    }   


    /**
     * 通过where获取所有数据
     *
     * @param array $arr_where
     * @param array $arr_option
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function get_all_by_whereIn( array $ids = [] , array $arr_option = [])
    {
        return Equities::whereIn('id' , $ids )->commonget($arr_option);

    }

}